package com.nbsaas.boot.project.rest.resource;

import com.nbsaas.boot.project.api.apis.ProjectFunctionApi;
import com.nbsaas.boot.project.data.entity.ProjectFunction;
import com.nbsaas.boot.project.api.domain.request.ProjectFunctionRequest;
import com.nbsaas.boot.project.api.domain.response.ProjectFunctionResponse;
import com.nbsaas.boot.project.api.domain.simple.ProjectFunctionSimple;
import com.nbsaas.boot.project.rest.convert.ProjectFunctionSimpleConvert;
import com.nbsaas.boot.project.rest.convert.ProjectFunctionEntityConvert;
import com.nbsaas.boot.project.rest.convert.ProjectFunctionResponseConvert;
import com.nbsaas.boot.project.data.repository.ProjectFunctionRepository;

import java.io.Serializable;
import com.nbsaas.boot.jpa.data.core.BaseResource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import org.springframework.data.jpa.repository.support.JpaRepositoryImplementation;

import java.util.function.Function;
import com.nbsaas.boot.rest.request.PageRequest;
import com.nbsaas.boot.rest.response.ListResponse;
import com.nbsaas.boot.project.api.domain.request.ProjectFunctionSearch;
/**
*   业务接口实现
*/
@Transactional
@Service
public class ProjectFunctionResource extends BaseResource<ProjectFunction,ProjectFunctionResponse, ProjectFunctionSimple, ProjectFunctionRequest>  implements ProjectFunctionApi {

    @Resource
    private ProjectFunctionRepository projectFunctionRepository;

    @Override
    public JpaRepositoryImplementation<ProjectFunction, Serializable> getJpaRepository() {
        return projectFunctionRepository;
    }

    @Override
    public Function<ProjectFunction, ProjectFunctionSimple> getConvertSimple() {
        return new ProjectFunctionSimpleConvert();
    }

    @Override
    public Function<ProjectFunctionRequest, ProjectFunction> getConvertForm() {
        return new ProjectFunctionEntityConvert();
    }

    @Override
    public Function<ProjectFunction, ProjectFunctionResponse> getConvertResponse() {
        return new ProjectFunctionResponseConvert();
    }



    @Override
    public ListResponse<ProjectFunctionSimple> list(PageRequest request) {
        ProjectFunctionSimpleConvert convert=new ProjectFunctionSimpleConvert();
        if (request instanceof ProjectFunctionSearch){
             ProjectFunctionSearch searchRequest=(ProjectFunctionSearch)request;
             convert.setFetch(searchRequest.getFetch());
        }
        return listSimple(request,convert);
    }

}


